package com.dbh.company.buildbook;

import cn.hutool.core.lang.Console;
import cn.hutool.http.HttpRequest;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.alibaba.fastjson.JSONObject;
import com.dbh.company.buildbook.bean.ProjectData;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataFormat;

import java.util.ArrayList;
import java.util.List;

/**
 * @author dongbanghui
 * @create 2023/9/21
 */
public class AroundProject {

    public static void main(String[] args) {
        String url = "https://backend-mr.ke.com/v1/projects/around-project?projectConfigId=17999";
        String jsonStr = HttpRequest.get(url)
                .cookie("crosSdkDT2019DeviceId=-uudqok-p0z6tw-u5tozzmsej9s39l-t6zeqcw9i; ketest-env=production; _ga=GA1.2.2121015128.1686129466; wx_device_id=bUTx-Zs85VX-EJ38i6V8ZKBFvZtdlNd_7n7X1cq3OrE=; ketest-session=4sh1l16dapt8cdy2qi7xofhzhjhrs5jr; ketest-user=eyJsb2dpbl91c2VyIjogIjEwMDAwMDAwMjkxMzg0OTgiLCAiYWNjb3VudCI6ICJkb25nYmFuZ2h1aTAwMSIsICJhY2NvdW50U3lzdGVtSWQiOiAiZW1wbG95ZWUiLCAiYXZhdGFyIjogIm51bGwiLCAiYmlydGhkYXkiOiAibnVsbCIsICJidXNpbmVzc1Rva2VuIjogIjIuMDExMWE5YmViMjg0Mzg1YTlmMDAwMWNiNTRjZDY5YzgxZmNmMzUyZTUxIiwgImNvcnBJZCI6ICJudWxsIiwgImRpc3BsYXlOYW1lIjogIlx1ODQ2M1x1NWUyZVx1OGY4OSIsICJlbWFpbCI6ICJkb25nYmFuZ2h1aTAwMUBrZS5jb20iLCAiZ2VuZGVyIjogIk1BTEUiLCAiaWQiOiAiMTAwMDAwMDAyOTEzODQ5OCIsICJtZmFBdXRoTWV0aG9kTGV2ZWwiOiAiMjE0NzQ4MzY0NyIsICJwYXNzZWRNZmFSZWFzb24iOiAiaXBXaGl0ZUxpc3QiLCAicGhvbmUiOiAiMTg1MDE5OTI1OTQiLCAicmVhbE5hbWUiOiAiXHU4NDYzXHU1ZTJlXHU4Zjg5IiwgInNlcnZpY2VJZCI6ICJjbG91ZC1sb2dpbi1zZWMua2UuY29tIiwgInN0YXRlIjogIk5PUk1BTCIsICJ0Z3RJZCI6ICJUR1QtMTI0NzQxLVU1MEg3RXRyVG9CMnFCZXcxNDJSUXpTWllWakdMTUE5M1B2Tlp3WlRpTjdlQk5NbDNRTnNMTUNOLWRwSmU4SWJOTGcta2UuY29tIiwgInVjaWQiOiAiMTAwMDAwMDAyOTEzODQ5OCIsICJ1Y25hbWUiOiAiXHU4NDYzXHU1ZTJlXHU4Zjg5IiwgInVpZCI6ICIxMDAwMDAwMDI5MTM4NDk4IiwgInVzZXJfY29kZSI6ICIyOTEzODQ5OCIsICJ1c2VyVGFnIjogIjAiLCAidmVyc2lvbiI6ICI3NTMiLCAiemhpZGFvX3VjaWQiOiAiMjExMDAwMDAwNDA5NjgwOSIsICJuZXh0X3VybCI6ICJodHRwOi8va2V0ZXN0LmtlLmNvbS8jLyJa2V0ZXN0LXVzZXI%3D9; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22ce301845-8fe2-4a00-96fb-8f5ac09fbf35%22%2C%22first_id%22%3A%2218976818cbd94a-066522c3f35ba78-7e565470-2073600-18976818cbe2427%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22%24device_id%22%3A%2218976818cbd94a-066522c3f35ba78-7e565470-2073600-18976818cbe2427%22%7D; factory_token=2.0111a9beb284385a9f0001cb540bfa0c9d3af67b53; _ga_F0DQ6TTSVW=GS1.2.1695120058.39.0.1695120058.60.0.0; lianjia_uuid=f592b012-722a-4fbd-ab97-2d8469a10cca; login_ucid=1000000029138498; security_ticket=p6iISpggdp62RD1SDWfWEIE6tckazpYVFRCq+/oykmTxUVmJFzdY5brnYdcKPNNa2+E3yIQEIhQ5BgYMyuPd7G/ukxtvw8SHEbEuicyKGZ7TGQma9+GA1vacPuoZNwKR4FgZ/Zbk6oZSRraovwleqjtWUd3TrTGV8sY/RbRDHYc=; security_ticket_test=A9KsG1ZzAkY56B9URDfaT75YMmVxGLVuESQ0+YX0utmh0sYiH03oV0BpJgt+6wOWvqeGMrqeQMBnbXQ/aKzedSo1fXTcDYqRifOWAyYZo1BXpIguMdUPqKz1rGVZmH4xBezTC8b5UQjXEOT1kvmJo2C/d5tZKi4dBVt3JL/w6co=; mr_backend_login_user=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzZXNzaW9uSWQiOiIyLjAwMTIwZWY5YzQ4NzlmMWRlOTAzYTc0Nzc2MTYyZTE2ZTgifQ.wbEaZXtxlmEGarRbWqKxRBK0cvzqlASFeEsF2Wk-Fws; mr_backend_service_uid=1000000029138498; lianjia_ssid=6136b540-c8fb-4aaf-9315-6be0b5fb9c8a")
                .execute().body();
        ProjectData projectData = JSONObject.parseObject(jsonStr, ProjectData.class);
        List<ProjectData.Project> data = projectData.getData();
        ExcelWriter writer = ExcelUtil.getWriter("D:\\data\\work\\file\\楼书\\楼书1.0\\"+"合肥市明君家园"+".xlsx");
        List<String> headList = new ArrayList<>();
        headList.add("project_no");
        headList.add("resblock_id");
        headList.add("first(project_name)");
        writer.setColumnWidth(0, 20);
        writer.setColumnWidth(1, 20);
        writer.setColumnWidth(2, 20);
        // 写标题
        writer.writeSecHeadRow(headList);
        // 文本格式cellStyle
        DataFormat textFormat = writer.getWorkbook().createDataFormat();
        CellStyle textCellStyle = writer.getWorkbook().createCellStyle();
        textCellStyle.setDataFormat(textFormat.getFormat("@"));
        List<List<Object>> rowList = new ArrayList<>();
        for (ProjectData.Project project : data) {
            List<Object> cellList = new ArrayList<>();
            String name = project.getName();
            Long projectNum = project.getProjectNum();
            String resblockId = project.getResblockId();
            cellList.add(projectNum);
            cellList.add(resblockId);
            cellList.add(name);
            Console.log(projectNum + ",");
            rowList.add(cellList);
        }
        writer.write(rowList, true);

//        writer.close();
    }

}
